<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the number of rows modified by the last INSERT, UPDATE, or 
  DELETE query executed</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.sqlsrv-rollback.html">sqlsrv_rollback</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sqlsrv-send-stream-data.html">sqlsrv_send_stream_data</a></div>
 <div class="up"><a href="ref.sqlsrv.html">SQLSRV 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.sqlsrv-rows-affected" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sqlsrv_rows_affected</h1>
  <p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">sqlsrv_rows_affected</span> &mdash; <span class="dc-title">Returns the number of rows modified by the last INSERT, UPDATE, or 
  DELETE query executed</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.sqlsrv-rows-affected-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>sqlsrv_rows_affected</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>
   )</div>

  <p class="para rdfs-comment">
   Returns the number of rows modified by the last INSERT, UPDATE, or DELETE 
   query executed. For information about the number of rows returned by a SELECT 
   query, see <span class="function"><a href="function.sqlsrv-num-rows.html" class="function">sqlsrv_num_rows()</a></span>.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.sqlsrv-rows-affected-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">stmt</code></em></dt>

     <dd>

      <p class="para">
       The executed statement resource for which the number of affected rows is returned.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.sqlsrv-rows-affected-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the number of rows affected by the last INSERT, UPDATE, or DELETE query. 
   If no rows were affected, 0 is returned. If the number of affected rows cannot 
   be determined, -1 is returned. If an error occurred, <strong><code>FALSE</code></strong> is returned.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.sqlsrv-rows-affected-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2125">
    <p><strong>Example #1 <span class="function"><strong>sqlsrv_rows_affected()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$serverName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"serverName\sqlexpress"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$connectionInfo&nbsp;</span><span style="color: #007700">=&nbsp;array(&nbsp;</span><span style="color: #DD0000">"Database"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"dbName"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UID"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"PWD"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"password"&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_connect</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$serverName</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$connectionInfo</span><span style="color: #007700">);<br />if(&nbsp;</span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"UPDATE&nbsp;Table_1&nbsp;SET&nbsp;data&nbsp;=&nbsp;?&nbsp;WHERE&nbsp;id&nbsp;=&nbsp;?"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$params&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"updated&nbsp;data"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_query</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$params</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$rows_affected&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_rows_affected</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$stmt</span><span style="color: #007700">);<br />if(&nbsp;</span><span style="color: #0000BB">$rows_affected&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}&nbsp;elseif(&nbsp;</span><span style="color: #0000BB">$rows_affected&nbsp;</span><span style="color: #007700">==&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"No&nbsp;information&nbsp;available.&lt;br&nbsp;/&gt;"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$rows_affected</span><span style="color: #007700">.</span><span style="color: #DD0000">"&nbsp;rows&nbsp;were&nbsp;updated.&lt;br&nbsp;/&gt;"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.sqlsrv-rows-affected-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.sqlsrv-num-rows.html" class="function" rel="rdfs-seeAlso">sqlsrv_num_rows()</a> - Retrieves the number of rows in a result set</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.sqlsrv-rollback.html">sqlsrv_rollback</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sqlsrv-send-stream-data.html">sqlsrv_send_stream_data</a></div>
 <div class="up"><a href="ref.sqlsrv.html">SQLSRV 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
